package com.wicket.okrdataassets.run;

//import com.douliwan.DouliwanHeader;
import com.wicket.okrdataassets.common.util.RedisUtil;
import com.wicket.okrdataassets.common.util.CommonFunctionHelper;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.annotation.Resource;

/**
 *
 *
 * @version 1.0
 */
@SpringBootApplication(scanBasePackages = {"com.wicket.okrdataassets", "com.wicket.okrdataassets.common.mq.config", "com.wicket.okrdataassets"})
@MapperScan("com.wicket.okrdataassets.dal.mapper.mbg")
@ComponentScan(basePackages = {"com.wicket.okrdataassets"})
@EnableTransactionManagement
@EnableFeignClients(basePackages = {"com.wicket.okrcomponent.integration", "com.wicket.okrframework.integration","com.wicket.okrcalc.integration"})
public class ApplicationRunner extends SpringBootServletInitializer implements CommandLineRunner {

    @Value("${security.db.address}")
    private String dbAddress;

    @Value("${security.db.account}")
    private String dbAccount;

    @Value("${security.db.password}")
    private String dbPassword;

    @Value("${file.path}")
    private String filePath;

    @Resource
    private RedisUtil redisUtil;

//    private static DouliwanHeader douliwan = new DouliwanHeader();
    private static final Logger log = LoggerFactory.getLogger(ApplicationRunner.class);

    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(ApplicationRunner.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        log.info("app start");
        //get();

//        String useFlag = System.getProperty("use.douliwan");
//        String str = "";
//        if(useFlag!=null && useFlag.equals("use")){
////            str = douliwan.loadInfo();
//            System.out.println("douliwan:启动");
//        }
//        CommonFunctionHelper.setSecStr(str);
        CommonFunctionHelper.setFilePath(filePath);
        CommonFunctionHelper.getConfigInfo().put("security.db.address",dbAddress);
        CommonFunctionHelper.getConfigInfo().put("security.db.account",dbAccount);
        CommonFunctionHelper.getConfigInfo().put("security.db.password",dbPassword);
        CommonFunctionHelper.setRedisUtil(redisUtil);
    }
}
